package cn.com.nes.site.entity.em.crm.customer;

import cn.com.nes.common.exception.NoSuchEnumException;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 客户文件类别 枚举
 *  值域对应 t_param 表 param_type=29
 */
@Slf4j
public enum CustomerFileTypeEnum {

    _01("01", "宣传资料"),
    _02("02", "公司产品简介"),
    _03("03", "身份证"),
    _04("04", "户口本"),
    _05("05", "旧设备与户主合影"),
    _06("06", "特殊情况证明"),
    _07("07", "低保户或五保户资格证明"),
    ;

    private String key;

    private String value;

    CustomerFileTypeEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public static String getVal(String key) {
        Map<String, String> map = new HashMap<>();
        for (CustomerFileTypeEnum value : values()) {
            map.put(value.getKey(), value.getValue());
        }
        return map.get(String.valueOf(key));
    }

    public static CustomerFileTypeEnum getEnum(String key) {
        Map<String, CustomerFileTypeEnum> map = new HashMap<>();
        for (CustomerFileTypeEnum customerFileTypeEnum : values()) {
            map.put(customerFileTypeEnum.getKey(), customerFileTypeEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的客户文件类型");
        }
        return map.get(String.valueOf(key));
    }

    public static String enumConvertKeyToValue(String key) {
        String val = "";
        try {
            val = getEnum(key).getValue();
        } catch (NoSuchEnumException e) {
            log.warn("{}, convert key to value error, key:[{}], cause:[{}]", e.getStackTrace()[0].getFileName(), key, e.getMessage());
        }
        return val;
    }


}
